//
//  Extension+UIImage.swift
//  Weibo
//
//  Created by vane on 16/8/18.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

extension UIImage{
    
    // 自定义表情键盘中获取image
    class func emoticonsImage(emoticonModel: GYEmoticonModel) -> UIImage?{
        let png = emoticonModel.png ?? ""
        let path = emoticonModel.path ?? ""
        let image = UIImage(named: "\(path)\(png)", inBundle: GYEmoticonTools.shardTools.emoticonsBundle, compatibleWithTraitCollection: nil)
        return image
    }

    
    class func dealImageScale(image: UIImage, width: CGFloat) -> UIImage{

        if image.size.width < width {
            return image
        }
        
        let height = image.size.height*width/image.size.width

        let rect = CGRect(x: 0, y: 0, width: width, height: height)
        
        // 开启上下文
        UIGraphicsBeginImageContext(rect.size)
        // 把内容渲染到上下文中
        image.drawInRect(rect)
        // 从上下文获取内容
        let result = UIGraphicsGetImageFromCurrentImageContext()
        // 关闭上下文
        UIGraphicsEndImageContext()
        
        return result
    }

    
    
    
}
